package cn.jb698.codec.msm.generator.v5base.beans;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import cn.jb698.codec.msm.generator.util.CodecCfgObjUtils;
import cn.jb698.codec.msm.generator.util.CodecGeneUtils;

/**
 * 增删改查配置-表对象配置
 * 
 * @author Administrator(LiuJianbin)
 * @date 2020-01-06
 */
public class BcrudCfgTableObj{
    
    // 通用属性列表  ///////////////////////////////////////////////////
    // 默认必设的值. dbType , basePackage , tableName , modelJavaTypeName . [ pkColumns , otherColumns ].

    // 表级别主要信息字段 Start ////////////////////////////

    /**
     * 项目包路径,例: cn.jb698.projxx
     */
    private String projPackage ; 

    /**
     * 基本包.默认 ${projPackage} + ".bcrud"
     * 例: cn.jb698.projxx.bcrud
     */
    private String basePackage;


    /**
     * 数据库类型.例: mysql , oracle
     */
    private String dbType;

    /**
     * 表名称,不含特殊字符,例: dt_table_name
     */
    private String tableName;

    /**
     * 表级别的备注内容,例:abc
     */
    private String comment;

    /**
     * 填入字符串的备注内容,如"abc" 转换后为: \"abc\" , 即值= comment.replaceAll("\"", "\\\\\"")
     */
    private String commentForStr;

    /**
     * 填入字符串的备注内容,如"abc" 转换后为: \"abc\" , 即值= comment.replaceAll("\"", "\\\\\"")
     */
    private String commentForComment;

    /**
     * 建表的DDL语句
     */
    private String createTableDdl;

    /**
     * 建表DDL语句注释,即值= createTableDdl.replaceAll("/","\\/")
     */
    private String createTableDdlForComment;

    /**
     * 查询更新时使用的别名,默认"t" , 例: t
     */
    private String tableAlias = "t";

    /**
     * 指定主键字段,(当该数据有值时,替换原有的主键字段)(不需要数据库配置的主键),
     */
    private String[] primKeyColumns;

    /**
     * 忽略生成的字段,(当该数据有值时,生成的json将忽略该字段),在版本迭代涉及字段淘汰时使用
     */
    private String[] ignoreColumns;

    // 表级别主要信息字段 End ////////////////////////////

    /**
     * 是否包含swagger属性说明
     */
    private Boolean hasSwaggerUi = false;

    /**
     * 是否包含Persistence注解
     */
    private Boolean hasPersistence = false;

    /**
     * 是否包含Baomidou实现注解
     */
    private Boolean hasBaomidou = false;

    /**
     * 是否自动截取字符串.
     */
    private Boolean hasAutoCutLengh = false;

    /**
     * 主键字段列表
     */
    private List<BcrudCfgColumnObj> pkColumns = new ArrayList<>();

    /**
     * 其它字段(非主键)列表,
     */
    private List<BcrudCfgColumnObj> otherColumns = new ArrayList<>();
    
    /**
     * 所有字段属性列表,从pkColumns 和 otherColumns 相结合
     */
    private List<BcrudCfgColumnObj> columns = new ArrayList<>();

    /**
     * 本表的查询类SQL字符串(类似视图的概念)
     */
    private String querySqlStr;

    /**
     * 查询字段的SQL
     */
    private String columnsSql;

    /**
     * from开始的Sql内容
     */
    private String fromSql;

    /**
     * 初始查询条件SQL,如 查询语句里带的 WHERE col1 = value1 ,将转换为 col1 = value1
     */
    private String initCriteriaSql;

    /**
     * 最后的group by SQL 的内容.
     */
    private String lastGrpbySql;

    /**
     * inner join 操作的表
     */
    private List<BcrudCfgTableObj> inJoinTables = new ArrayList<>(); // inner join 操作的表(虚拟表)

    /**
     * 表达式的列统计
     */
    private Integer expressColumnCnt = 0;

    /**
     * import的规则列表
     */
    private List<String> importRuleList = new ArrayList<>();


    // 各文件层的属性Map,例: entity,mapper,service,serviceImpl,ctrler
    private Map<String,BcrudCfgJavaFileObj> fileObjMap = new HashMap<>();

    // 文件对象-entity
//    private BcrudCfgJavaFileObj fileObjEntity;

//    // 文件对象-mapper
//    private BcrudCfgJavaFileObj fileObjMapper;
//
//    // 文件对象-service
//    private BcrudCfgJavaFileObj fileObjService;
//
//    // 文件对象-ctrler
//    private BcrudCfgJavaFileObj fileObjCtrler;

    // 自定义实体的名称(JavaTypeName)
    private String defEntityObjName;


    // 统计和计算类字段 Start ////////////////////////////

    /**
     * 主键字段数组长度 .
     */
    private Integer pkColumnsLength;

    /**
     * 其它字段数组长度 .
     */
    private Integer otherColumnsLength;

    /**
     * 字段的Java类列表(全路径)( import 使用的类 )
     */
    private List<String> columnJavaTypeList;

    // 统计和计算类字段 End ////////////////////////////

    // 数据类型转换类 Start ////////////////////////////

    /**
     * java类型映射-Double类型,默认Double,可映射为BigDecimal
     */
    private String javaTypeDouble;

    // 数据类型转换类 End ////////////////////////////
    
    
    
    // 模块功能规划 Start //////////////////////////

    /**
     * 模块路径,用于规划请求路径,功能路径,默认"system",
     * 取值时,没有斜杠开头和结尾
     */
    private String modulePath;
    
    /**
     * 模块名称,用于规划权限码等,默认"system",
     * 取值时,没有斜杠开头和结尾
     */
    private String moduleName;

    /**
     * 业务名称,默认表名
     */
    private String businessName;
    
    /**
     * 权限码路径,默认通过modulePath计算
     */
    private String powerCodePath;

    // 模块功能规划 End //////////////////////////
    
    // 扩展属性 Start ////////////////////////////////

    /**
     * 扩展属性
     */
    private Map<String,Object> extPropMap;
    
    // 扩展属性 End ////////////////////////////////
    
    
    
    /**
     * label的名称
     */
    private String labelName;

    public BcrudCfgTableObj() {

    }

    public BcrudCfgTableObj(String tableName, String tableAlias) {
        super();
        this.tableName = tableName;
        this.tableAlias = tableAlias;
    }

//    public BcrudCfgTableObj(String tableName, String tableAlias, String modelJavaTypeName, String[] primKeyColumns) {
//        super();
//        this.tableName = tableName;
//        this.tableAlias = tableAlias;
//        this.modelJavaTypeName = modelJavaTypeName;
//        this.primKeyColumns = primKeyColumns;
//    }

    /**
     * 配置是否包含swaggerui配置
     * 
     * @param hasSwaggerUi
     * @return
     */
    public BcrudCfgTableObj doHasSwaggerUi(boolean hasSwaggerUi) {
        this.hasSwaggerUi = hasSwaggerUi;
        return this;
    }

    /**
     * 是否自动截取字符串长度
     * 
     * @param hasAutoCutLengh
     * @return
     */
    public BcrudCfgTableObj doHasAutoCutLengh(boolean hasAutoCutLengh) {
        this.hasAutoCutLengh = hasAutoCutLengh;
        return this;
    }

    /**
     * 是否包含注解
     * 
     * @param hasPersistence
     * @return
     */
    public BcrudCfgTableObj doHasPersistence(boolean hasPersistence) {
        this.hasPersistence = hasPersistence;
        return this;
    }

    /**
     * 是否包含注解
     * 
     * @param hasPersistence
     * @return
     */
    public BcrudCfgTableObj doHasBaomidou(boolean hasBaomidou) {
        this.hasBaomidou = hasBaomidou;
        return this;
    }

    /**
     * 设置表名称
     * 
     * @param tableName
     * @return
     */
    public BcrudCfgTableObj doSetTableName(String tableName) {
        this.tableName = tableName;
        return this;
    }

//    /**
//     * 设置类名
//     * 
//     * @param modelJavaTypeName
//     */
//    public BcrudCfgTableObj doSetModelJavaTypeName(String modelJavaTypeName) {
//        this.modelJavaTypeName = modelJavaTypeName;
//        return this;
//    }

    /**
     * 设置主键
     * 
     * @param primKeyColumns
     * @return
     */
    public BcrudCfgTableObj doSetPrimKeyColumns(String[] primKeyColumns) {
        this.primKeyColumns = primKeyColumns;
        return this;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableAlias() {
        return tableAlias;
    }

    public void setTableAlias(String tableAlias) {
        this.tableAlias = tableAlias;
    }

    public String[] getPrimKeyColumns() {
        return primKeyColumns;
    }

    public void setPrimKeyColumns(String[] primKeyColumns) {
        this.primKeyColumns = primKeyColumns;
    }

//    public String getModelJavaTypeName() {
//        if (modelJavaTypeName == null && tableName != null) {
//            String tmp_propName = CodecGeneUtils.parseColumnNameToPropName(tableName);
//            tmp_propName = tmp_propName.substring(0, 1).toUpperCase() + tmp_propName.substring(1);
//            modelJavaTypeName = tmp_propName;
//        }
//        return modelJavaTypeName;
//    }
//    public void setModelJavaTypeName(String modelJavaTypeName) {
//        this.modelJavaTypeName = modelJavaTypeName;
//    }

    public String[] getIgnoreColumns() {
        return ignoreColumns;
    }

    public void setIgnoreColumns(String[] ignoreColumns) {
        this.ignoreColumns = ignoreColumns;
    }

    public Boolean getHasSwaggerUi() {
        return hasSwaggerUi;
    }

    public void setHasSwaggerUi(Boolean hasSwaggerUi) {
        this.hasSwaggerUi = hasSwaggerUi;
    }

    public Boolean getHasPersistence() {
        return hasPersistence;
    }

    public void setHasPersistence(Boolean hasPersistence) {
        this.hasPersistence = hasPersistence;
    }

    public Boolean getHasAutoCutLengh() {
        return hasAutoCutLengh;
    }

    public void setHasAutoCutLengh(Boolean hasAutoCutLengh) {
        this.hasAutoCutLengh = hasAutoCutLengh;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getCommentForStr() {
        if (this.commentForStr != null) {
            return this.commentForStr;
        } else if (this.comment != null) {
            this.commentForStr = CodecCfgObjUtils.parseCommentForStr(comment);
        }
        return this.commentForStr;
    }

    public void setCommentForStr(String commentForStr) {
        this.commentForStr = commentForStr;
    }

    public String getCommentForComment() {
        if (this.commentForComment != null) {
            return this.commentForComment;
        } else if (this.comment != null) {
            this.commentForComment = CodecCfgObjUtils.parseCommentForComment(comment);
        }
        return commentForComment;
    }

    public void setCommentForComment(String commentForComment) {
        this.commentForComment = commentForComment;
    }

    public Boolean getHasBaomidou() {
        return hasBaomidou;
    }

    public void setHasBaomidou(Boolean hasBaomidou) {
        this.hasBaomidou = hasBaomidou;
    }

    public String getCreateTableDdl() {
        return createTableDdl;
    }

    public void setCreateTableDdl(String createTableDdl) {
        this.createTableDdl = createTableDdl;
    }

    public String getCreateTableDdlForComment() {
        if (this.createTableDdlForComment != null) {
            return this.createTableDdlForComment;
        } else if (this.createTableDdl != null) {
            this.createTableDdlForComment = CodecCfgObjUtils.parseCommentForComment(createTableDdl);
        }
        return this.createTableDdlForComment;
    }

    public void setCreateTableDdlForComment(String createTableDdlForComment) {
        this.createTableDdlForComment = createTableDdlForComment;
    }

    public String getInitCriteriaSql() {
        return initCriteriaSql;
    }

    public void setInitCriteriaSql(String initCriteriaSql) {
        this.initCriteriaSql = initCriteriaSql;
    }

    public Integer getExpressColumnCnt() {
        return expressColumnCnt;
    }

    public void setExpressColumnCnt(Integer expressColumnCnt) {
        this.expressColumnCnt = expressColumnCnt;
    }

    public String getDbType() {
        return dbType;
    }

    public void setDbType(String dbType) {
        this.dbType = dbType;
    }

    public String getBasePackage() {
        return basePackage;
    }

    public void setBasePackage(String basePackage) {
        this.basePackage = basePackage;
    }

    public List<BcrudCfgColumnObj> getPkColumns() {
        if(Objects.isNull(pkColumns)) {
            pkColumns = new ArrayList<>();
        }
        return pkColumns;
    }

    public void setPkColumns(List<BcrudCfgColumnObj> pkColumns) {
        this.pkColumns = pkColumns;
    }

    public List<BcrudCfgColumnObj> getOtherColumns() {
        if(Objects.isNull(otherColumns)) {
            otherColumns = new ArrayList<>();
        }
        return otherColumns;
    }

    public void setOtherColumns(List<BcrudCfgColumnObj> otherColumns) {
        this.otherColumns = otherColumns;
    }

    public String getQuerySqlStr() {
        return querySqlStr;
    }

    public void setQuerySqlStr(String querySqlStr) {
        this.querySqlStr = querySqlStr;
    }

    public String getLastGrpbySql() {
        return lastGrpbySql;
    }

    public void setLastGrpbySql(String lastGrpbySql) {
        this.lastGrpbySql = lastGrpbySql;
    }

    public List<BcrudCfgTableObj> getInJoinTables() {
        return inJoinTables;
    }

    public void setInJoinTables(List<BcrudCfgTableObj> inJoinTables) {
        this.inJoinTables = inJoinTables;
    }

    public String getColumnsSql() {
        return columnsSql;
    }

    public void setColumnsSql(String columnsSql) {
        this.columnsSql = columnsSql;
    }

    public String getFromSql() {
        return fromSql;
    }

    public void setFromSql(String fromSql) {
        this.fromSql = fromSql;
    }

    public String getProjPackage() {
        if(Objects.isNull(projPackage) || StringUtils.isBlank(projPackage) ) {
            String calcPackage = this.getBasePackage();
            if(calcPackage.endsWith("crud")) {
                int idx = calcPackage.lastIndexOf(".");
                if(idx > 0 ) {
                    calcPackage = calcPackage.substring(0,idx);
                    projPackage = calcPackage;
                }
            }else {
                projPackage = calcPackage;
            }
        }
        return projPackage;
    }

    public void setProjPackage(String apiPackage) {
        this.projPackage = apiPackage;
    }

//    public String getMapperJavaType() {
//        if (mapperJavaType == null) {
//            mapperJavaType = (this.getMapperJavaTypePackage() + "." + this.getMapperJavaTypeName());
//        }
//        return mapperJavaType;
//    }
//
//    public void setMapperJavaType(String mapperJavaType) {
//        this.mapperJavaType = mapperJavaType;
//    }
//
//    public String getModelServiceJavaType() {
//        if (modelServiceJavaType == null) {
//            modelServiceJavaType = (this.getModelServiceJavaTypePackage() + "." + this.getModelServiceJavaTypeName());
//        }
//        return modelServiceJavaType;
//    }
//
//    public void setModelServiceJavaType(String modelServiceJavaType) {
//        this.modelServiceJavaType = modelServiceJavaType;
//    }
//
//    public String getCtrlerJavaType() {
//        if (ctrlerJavaType == null) {
//            ctrlerJavaType = (this.getCtrlerJavaTypePackage() + "." + this.getCtrlerJavaTypeName());
//        }
//        return ctrlerJavaType;
//    }
//
//    public void setCtrlerJavaType(String ctrlerJavaType) {
//        this.ctrlerJavaType = ctrlerJavaType;
//    }
//
//    public String getMapperXmlNamespace() {
//        if (mapperXmlNamespace == null) {
//            mapperXmlNamespace = this.getMapperJavaType();
//        }
//        return mapperXmlNamespace;
//    }
//
//    public void setMapperXmlNamespace(String mapperXmlNamespace) {
//        this.mapperXmlNamespace = mapperXmlNamespace;
//    }

    public Integer getPkColumnsLength() {
        if (pkColumnsLength == null) {
            pkColumnsLength = this.getPkColumns().size();
        }
        return pkColumnsLength;
    }

    public void setPkColumnsLength(Integer pkColumnsLength) {
        this.pkColumnsLength = pkColumnsLength;
    }

    public Integer getOtherColumnsLength() {
        if (otherColumnsLength == null) {
            otherColumnsLength = this.getOtherColumns().size();
        }
        return otherColumnsLength;
    }

    public void setOtherColumnsLength(Integer otherColumnsLength) {
        this.otherColumnsLength = otherColumnsLength;
    }

//    public String getMapperJavaTypePackage() {
//        if (mapperJavaTypePackage == null) {
//            mapperJavaTypePackage = (this.getBasePackage() + ".dao");
//        }
//        return mapperJavaTypePackage;
//    }
//
//    public void setMapperJavaTypePackage(String mapperJavaTypePackage) {
//        this.mapperJavaTypePackage = mapperJavaTypePackage;
//    }
//
//    public String getMapperJavaTypeName() {
//        if (mapperJavaTypeName == null) {
//            mapperJavaTypeName = (this.getModelJavaTypeName() + "Mapper");
//        }
//        return mapperJavaTypeName;
//    }
//
//    public void setMapperJavaTypeName(String mapperJavaTypeName) {
//        this.mapperJavaTypeName = mapperJavaTypeName;
//    }
//
//    public String getMapperJavaTypePropName() {
//        if (mapperJavaTypePropName == null) {
//            return mapperJavaTypePropName = (this.getModelJavaTypePropName() + "Mapper");
//        }
//        return mapperJavaTypePropName;
//    }
//
//    public void setMapperJavaTypePropName(String mapperJavaTypePropName) {
//        this.mapperJavaTypePropName = mapperJavaTypePropName;
//    }
//
//    public String getModelServiceJavaTypePackage() {
//        if (modelServiceJavaTypePackage == null) {
//            return modelServiceJavaTypePackage = (this.getBasePackage() + ".service");
//        }
//        return modelServiceJavaTypePackage;
//    }
//
//    public void setModelServiceJavaTypePackage(String modelServiceJavaTypePackage) {
//        this.modelServiceJavaTypePackage = modelServiceJavaTypePackage;
//    }
//
//    public String getModelServiceJavaTypeName() {
//        if (modelServiceJavaTypeName == null) {
//            return modelServiceJavaTypeName = (this.getModelJavaTypeName() + "Service");
//        }
//        return modelServiceJavaTypeName;
//    }
//
//    public void setModelServiceJavaTypeName(String modelServiceJavaTypeName) {
//        this.modelServiceJavaTypeName = modelServiceJavaTypeName;
//    }
//
//    public String getModelServiceJavaTypePropName() {
//        if (modelServiceJavaTypePropName == null) {
//            return modelServiceJavaTypePropName = (this.getModelJavaTypePropName() + "Service");
//        }
//        return modelServiceJavaTypePropName;
//    }
//
//    public void setModelServiceJavaTypePropName(String modelServiceJavaTypePropName) {
//        this.modelServiceJavaTypePropName = modelServiceJavaTypePropName;
//    }
//
//    public String getCtrlerJavaTypePackage() {
//        if (ctrlerJavaTypePackage == null) {
//            return ctrlerJavaTypePackage = (this.getBasePackage() + ".ctrler");
//        }
//        return ctrlerJavaTypePackage;
//    }
//
//    public void setCtrlerJavaTypePackage(String ctrlerJavaTypePackage) {
//        this.ctrlerJavaTypePackage = ctrlerJavaTypePackage;
//    }
//
//    public String getCtrlerJavaTypeName() {
//        if (ctrlerJavaTypeName == null) {
//            return ctrlerJavaTypeName = (this.getModelJavaTypeName() + "Ctrler");
//        }
//        return ctrlerJavaTypeName;
//    }
//
//    public void setCtrlerJavaTypeName(String ctrlerJavaTypeName) {
//        this.ctrlerJavaTypeName = ctrlerJavaTypeName;
//    }
//
//    public String getCtrlerJavaTypePropName() {
//        if (ctrlerJavaTypePropName == null) {
//            return ctrlerJavaTypePropName = (this.getModelJavaTypePropName() + "Ctrler");
//        }
//        return ctrlerJavaTypePropName;
//    }
//
//    public void setCtrlerJavaTypePropName(String ctrlerJavaTypePropName) {
//        this.ctrlerJavaTypePropName = ctrlerJavaTypePropName;
//    }

    public List<String> getColumnJavaTypeList() {
        if (columnJavaTypeList == null) {
            List<String> calc_columnJavaTypeList = CodecCfgObjUtils.doColumnJavaTypeListCalc(this);
            columnJavaTypeList = calc_columnJavaTypeList;
        }
        return columnJavaTypeList;
    }

    public void setColumnJavaTypeList(List<String> columnJavaTypeList) {
        this.columnJavaTypeList = columnJavaTypeList;
    }

    public String getJavaTypeDouble() {
        return javaTypeDouble;
    }

    public List<String> getImportRuleList() {
        return importRuleList;
    }

    public void setImportRuleList(List<String> importRuleList) {
        this.importRuleList = importRuleList;
    }

    public void setJavaTypeDouble(String javaTypeDouble) {
        this.javaTypeDouble = javaTypeDouble;
    }

//    public List<String> getModelImportList() {
//        if(modelImportList == null || modelImportList.isEmpty() ) {
//            modelImportList = CodecCfgObjUtils.doModelImportListCalc(this);
//        }
//        return modelImportList;
//    }
//
//    public void setModelImportList(List<String> modelImportList) {
//        this.modelImportList = modelImportList;
//    }
//
//    public List<String> getMapperImportList() {
//        if(mapperImportList == null || mapperImportList.isEmpty() ) {
//            mapperImportList = CodecCfgObjUtils.doMapperImportListCalc(this);
//        }
//        return mapperImportList;
//    }

//    public void setMapperImportList(List<String> mapperImportList) {
//        this.mapperImportList = mapperImportList;
//    }

    
    public String getModulePath() {
        if(Objects.isNull(modulePath)) {
            String calcPath = "system";
            modulePath = doCalcModulePath(calcPath);
        }
        return modulePath;
    }

    public String getModuleName() {
        if(Objects.isNull(moduleName)) {
            String dftName = "system";
            moduleName = dftName;
        }
        return moduleName;
    }

    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }

    public BcrudCfgTableObj setModulePath(String modulePath) {
        this.modulePath = doCalcModulePath(modulePath);
        return this;
    }

    public String getBusinessName() {
        if(Objects.isNull(businessName)) {
            businessName = this.getTableName();
        }
        return businessName;
    }

    public BcrudCfgTableObj setBusinessName(String businessName) {
        this.businessName = businessName;
        return this;
    }

    public String getLabelName() {
        if(Objects.isNull(labelName)) {
            String tmpComment = this.getComment();
            if(Objects.nonNull(tmpComment)) {
                labelName = CodecGeneUtils.calcTableLabelName(tmpComment) ;
            }
        }
        return labelName;
    }

    public BcrudCfgTableObj setLabelName(String labelName) {
        this.labelName = labelName;
        return this;
    }
    
    public String getPowerCodePath() {
        if(StringUtils.isBlank(powerCodePath)) {
            String calcPowerPath = this.getModulePath();
            calcPowerPath = calcPowerPath.replaceAll("/", ":");
            powerCodePath = calcPowerPath;
        }
        return powerCodePath;
    }

    public void setPowerCodePath(String powerCodePath) {
        this.powerCodePath = powerCodePath;
    }

    public Map<String, Object> getExtPropMap() {
        return extPropMap;
    }

    public void setExtPropMap(Map<String, Object> extPropMap) {
        this.extPropMap = extPropMap;
    }

    public List<BcrudCfgColumnObj> getColumns() {
        if(columns == null || columns.size() < 1 ) {
            List<BcrudCfgColumnObj> tmpPkColumns = this.getPkColumns();
            List<BcrudCfgColumnObj> tmpOtherColumns = this.getOtherColumns();
            columns = new ArrayList<>();
            columns.addAll(tmpPkColumns);
            columns.addAll(tmpOtherColumns);
        }
        return columns;
    }

    public void setColumns(List<BcrudCfgColumnObj> columns) {
        this.columns = columns;
    }
    

    public Map<String, BcrudCfgJavaFileObj> getFileObjMap() {
        return fileObjMap;
    }

    public void setFileObjMap(Map<String, BcrudCfgJavaFileObj> fileObjMap) {
        this.fileObjMap = fileObjMap;
    }

    public BcrudCfgJavaFileObj getFileObjEntity() {
        String mapKey = "fileObjEntity";
        Map<String, BcrudCfgJavaFileObj> fileObjMap = this.getFileObjMap();
        BcrudCfgJavaFileObj tmpFileObj = fileObjMap.get(mapKey);
        if(Objects.isNull(tmpFileObj)) {
            String tmpObjName = CodecGeneUtils.parseColumnNameToPropName(tableName);
            tmpObjName = tmpObjName.substring(0, 1).toUpperCase() + tmpObjName.substring(1);
            String packageNameExp = this.getBasePackage()+".model";
            List<String> importList = CodecCfgObjUtils.doModelImportListCalc(this);
            BcrudCfgJavaFileObj fileObj = new BcrudCfgJavaFileObj(tmpObjName, packageNameExp);
            fileObj.setOrder(0); // 最高优先级
            fileObj.setImportList(importList);

            tmpFileObj = fileObj;
            fileObjMap.put(mapKey, tmpFileObj);
        }
        return tmpFileObj;
    }
    public void setFileObjEntity(BcrudCfgJavaFileObj fileObjEntity) {
//        this.fileObjEntity = fileObjEntity;
        String mapKey = "fileObjEntity";
        this.getFileObjMap().put(mapKey, fileObjEntity);
    }

    public BcrudCfgJavaFileObj getFileObjMapper() {
        String mapKey = "fileObjMapper";
        Map<String, BcrudCfgJavaFileObj> fileObjMap = this.getFileObjMap();
        BcrudCfgJavaFileObj tmpFileObj = fileObjMap.get(mapKey);

        if(Objects.isNull(tmpFileObj)) {
            String tmpObjName = this.getFileObjEntity().getObjName()+"Mapper";
            String packageNameExp = this.getBasePackage()+".dao"; // 
            List<String> importList = CodecCfgObjUtils.doMapperImportListCalc(this);
            BcrudCfgJavaFileObj fileObj = new BcrudCfgJavaFileObj(tmpObjName, packageNameExp);
            fileObj.setImportList(importList);

            tmpFileObj = fileObj;
            fileObjMap.put(mapKey, tmpFileObj);
        }
        return tmpFileObj;
    }

    public void setFileObjMapper(BcrudCfgJavaFileObj fileObjMapper) {
//        this.fileObjMapper = fileObjMapper;
        String mapKey = "fileObjMapper";
        this.getFileObjMap().put(mapKey, fileObjMapper);
    }

    public BcrudCfgJavaFileObj getFileObjService() {
        String mapKey = "fileObjService";
        Map<String, BcrudCfgJavaFileObj> fileObjMap = this.getFileObjMap();
        BcrudCfgJavaFileObj tmpFileObj = fileObjMap.get(mapKey);
        
        if(Objects.isNull(tmpFileObj)) {
            String tmpObjName = this.getFileObjEntity().getObjName()+"Service";
            String packageNameExp = this.getBasePackage()+".service"; // 
//            List<String> importList = CodecCfgObjUtils.doMapperImportListCalc(this);
            BcrudCfgJavaFileObj fileObj = new BcrudCfgJavaFileObj(tmpObjName, packageNameExp);
//            fileObj.setImportList(importList);

            tmpFileObj = fileObj;
            fileObjMap.put(mapKey, tmpFileObj);
        }
        return tmpFileObj;
    }

    public void setFileObjService(BcrudCfgJavaFileObj fileObjService) {
//        this.fileObjService = fileObjService;
        String mapKey = "fileObjService";
        this.getFileObjMap().put(mapKey, fileObjService);
    }

    public BcrudCfgJavaFileObj getFileObjCtrler() {

        String mapKey = "fileObjCtrler";
        Map<String, BcrudCfgJavaFileObj> fileObjMap = this.getFileObjMap();
        BcrudCfgJavaFileObj tmpFileObj = fileObjMap.get(mapKey);
        
        if(Objects.isNull(tmpFileObj)) {
            String tmpObjName = this.getFileObjEntity().getObjName()+"Ctrler";
            String packageNameExp = this.getProjPackage()+".ctrler";
//            List<String> importList = CodecCfgObjUtils.do(this);
            BcrudCfgJavaFileObj fileObj = new BcrudCfgJavaFileObj(tmpObjName, packageNameExp);
//            fileObj.setImportList(importList);

            tmpFileObj = fileObj;
            fileObjMap.put(mapKey, tmpFileObj);
        }
        return tmpFileObj;
    }

    public void setFileObjCtrler(BcrudCfgJavaFileObj fileObjCtrler) {
//        this.fileObjCtrler = fileObjCtrler;
        String mapKey = "fileObjCtrler";
        this.getFileObjMap().put(mapKey, fileObjCtrler);
    }

    public String getDefEntityObjName() {
        return defEntityObjName;
    }

    public void setDefEntityObjName(String defEntityObjName) {
        this.defEntityObjName = defEntityObjName;
    }

    /**
     * 
     * @param columnName
     * @return
     */
    public BcrudCfgColumnObj doGetCfgColumnByColumn(String columnName) {
        BcrudCfgColumnObj columnObj = this.getPkColumns().stream().filter(obj->obj.getColumn().equals(columnName)).findFirst().orElse(null); 
        if(Objects.isNull(columnObj)) {
            columnObj = this.getOtherColumns().stream().filter(obj->obj.getColumn().equals(columnName)).findFirst().orElse(null); 
        }
        return  columnObj;
    }
    
    /**
     * 计算模块路径
     * @param calcPath
     * @return
     */
    private static String doCalcModulePath(String calcPath) {
        if(Objects.nonNull(calcPath)) {
            calcPath = calcPath.trim();
            calcPath = calcPath.replaceAll("\\\\", "/");
            if(calcPath.startsWith("/")) {
                calcPath = calcPath.substring(1);
            }
            if(calcPath.endsWith("/")) {
                calcPath = calcPath.substring(0,calcPath.length()-1);
            }
        }
        return calcPath ;
    }

}
